<?php
// $title = $_POST['title'];
// $content = $_POST['content'];
// $country=$_POST['country'];
// $types=$_POST['type'];
// if(!file_exists("uploads")){  //如果没有uploads文件夹 
// 	mkdir("uploads");  //自动创建一个uploads文件夹
// }
// print_r($_FILES);
// $path = $_FILES['myimg']['tmp_name'];
// move_uploaded_file($path,"uploads/".$_FILES['myimg']['name']);
// $img="uploads/".$_FILES['myimg']['name'];
// $addtime = time(); 


// $link = mysqli_connect("localhost","root","root","2113");
// $sql = "INSERT INTO news(title,content,country,types,photo,addtime) VALUES ('$title','$content','$country','$types','$img','$addtime')";

// $res =  mysqli_query($link,$sql);
// // 执行结果集获取数据



// header("Location:index.html");



// print_r($_POST);
// print_r($_FILES);

// 把获取的数据添加到数据库
$title = $_POST['title'];
$content = $_POST['content'];
$typeValue = $_POST['typeValue'];
$country = $_POST['country'];
// 文件存储 
if(!file_exists("uploads")){
	mkdir("uploads");
}

$path = $_FILES['imgFile']['tmp_name'];
$disPath = "uploads/".$_FILES['imgFile']['name'];
move_uploaded_file($path,$disPath);

// 添加时间
$addtime = time(); 

$link = mysqli_connect("localhost","root","root","2113");


$sql = "INSERT INTO news (title,content,typeValue,country,imgFileUrl,addtime) VALUES('$title','$content','$typeValue','$country','$disPath','$addtime')";


$res =  mysqli_query($link,$sql);

$arr = [];
if($res){
	$arr['info'] = "添加成功";
	$arr['status'] = 1;
}else{
	$arr['info'] = "添加失败";
	$arr['status'] = 0;
}


echo json_encode($arr);






// 更新之前的数据


?>

